<template>
  <div class="link-manager">
    <div class="query">
      <el-select
        v-model="query.type"
        style="width: 250px"
        clearable
        :placeholder="$t('query.请选择查询类型')"
      >
        <el-option label="item id" value="ItemId"> </el-option>
        <el-option label="Sku" value="sku"> </el-option>
        <el-option :label="$t('link.商品名称')" value="title"> </el-option>
      </el-select>
      <el-input
        clearable
        style="width: 250px; margin: 0 10px"
        v-model="query.key"
        :readonly="!query.type"
        :placeholder="query.type"
      ></el-input>
      <el-button type="primary" @click="getLinkManagerList(2)">{{
        $t("form.queryBtn")
      }}</el-button>
    </div>
    <el-table border :data="tableData">
      <el-table-column
        prop="ItemId"
        label="ITEM ID"
        minWidth="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="sku"
        label="Sku"
        minWidth="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="InventoryId"
        label="Inventory id"
        minWidth="100"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="title"
        :label="$t('link.商品墨西哥名称')"
        minWidth="200"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="AvailableQuantity"
        :label="$t('link.可售库存')"
        minWidth="50"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="SoldQuantity"
        :label="$t('link.已售库存')"
        minWidth="50"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="StartDate"
        :label="$t('link.开店时间')"
        minWidth="200"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="logistic"
        :label="$t('link.发货类型')"
        minWidth="200"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="price"
        :label="$t('link.价格Price')"
        minWidth="100"
        align="center"
      >
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.start"
        background
        :page-sizes="[15, 100, 200, 300, 400]"
        :page-size="page.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { linkManagerListApi, linkManagerListQueryApi } from "@/api";
import { cloneDeep } from "loadsh";
export default {
  name: "link-manager",
  data() {
    return {
      tableData: [],
      page: {
        start: 1,
        limit: 15,
      },
      total: 0,
      query: {
        type: "",
        key: "",
      },
    };
  },
  created() {
    this.getLinkManagerList();
  },
  methods: {
    async getLinkManagerList(type = 1) {
      let params = cloneDeep({
        ...this.page,
        start: this.page.start - 1,
      });
      if (this.query.type && this.query.key) {
        params[this.query.type] = this.query.key;
        const { data, total } = await linkManagerListApi(params);
        this.tableData = data;
        this.total = total;
        return;
      }
      const { data, total } = await linkManagerListApi(params);
      this.tableData = data;
      this.total = total;
    },
    handleSizeChange(e) {
      this.page.limit = e;
      this.getLinkManagerList();
    },
    handleCurrentChange(e) {
      this.page.start = e;
      this.getLinkManagerList();
    },
  },
};
</script>

<style lang="scss" scoped src="./link-manager.scss"></style>
